package LBS;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Control {//201621123021
    private static final String URL="jdbc:mysql://localhost:3306/library";
    private static final String NAME="root";
    private static final String PASSWORD="123456";
    private static Connection con=null;
public void addbook() throws Exception{//添加书籍
    book b=new book("science","time","universe");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection(URL, NAME, PASSWORD);
    String sql="" + "insert into book"+ "(subject,title,keyword)"+ "values("+ "?,?,?)";
    PreparedStatement ps=con.prepareStatement(sql);
    ps.setString(1,b.getSubject());
    ps.setString(2,b.getTitle());
    ps.setString(3,b.getKeyword());
    ps.execute();
}
public void update() throws Exception{//更新书籍
    book b=new book("science","relativity","nature");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection(URL,NAME,PASSWORD);
    String sql="update book set subject=?,title=?,keyword=? where title='time'";
    PreparedStatement ps=con.prepareStatement(sql);
    ps.setString(1,b.getSubject());
    ps.setString(2,b.getTitle());
    ps.setString(3,b.getKeyword());
    ps.execute();
}
public void delete() throws Exception{//删除书籍
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection(URL,NAME,PASSWORD);
    String sql="delete from book where title='relativity'";
    PreparedStatement ps=con.prepareStatement(sql);
    ps.execute();
}
}
